from itsdangerous import TimedJSONWebSignatureSerializer as Serializer
from django.conf import settings


def generate_access_token(openid):

    s = Serializer(settings.SECRET_KEY, expires_in=600)

    data = {'openid': openid}

    # 加密
    token = s.dumps(data)

    return token.decode()


def check_access_token(access_token):

    s = Serializer(settings.SECRET_KEY)

    data = s.loads(access_token)

    return data.get('openid')